﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Data;
using System.IO;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Text;

using Fcdbas.Platform.Properties;
using Fcdbas.Platform.Controls;
using Fcdbas.WinUI.Controls;
namespace Fcdbas.WinUI.Design
{
    public class DataSourceBindingDesigner : ComponentDesigner
    {
        DesignerVerb _designerVerb;
        //DesignerVerb _designerVerb1;

        public DataSourceBindingDesigner()
            : base()
        {
            _designerVerb = new DesignerVerb("Fcdbas 属性", new EventHandler(PopupPropertiesWindow));
            //_designerVerb1 = new DesignerVerb("生成 FunctionClass", new EventHandler(GenerateFunctionClass));
        }

        public override DesignerVerbCollection Verbs
        {
            get
            {
                if (base.Verbs != null)
                {
                    if (!base.Verbs.Contains(_designerVerb))
                        base.Verbs.Add(_designerVerb);
                    //if (!base.Verbs.Contains(_designerVerb1))
                    //    base.Verbs.Add(_designerVerb1);
                }

                return base.Verbs;
            }
        }

        protected void PopupPropertiesWindow(object sender, EventArgs args)
        {
            IWindowProperties dataSourceComponent = this.Component as IWindowProperties;
            if (dataSourceComponent == null)
            {
                MessageBox.Show("无效的 Fcdbase 组件。");
                return;
            }

            DataSourceBindingPropertiesEdit frmSetProperties = new DataSourceBindingPropertiesEdit((DataSourceBinding)this.Component);
            frmSetProperties.Text += this.Component.Site.Name;
            if (frmSetProperties.ShowDialog() == DialogResult.OK)
            {
                PropertyDescriptor statePrperty = TypeDescriptor.GetProperties(typeof(IComponentPropertyChanged))["PropertyChanged"];

                IComponentChangeService componentChangeService = this.Component.Site.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
                componentChangeService.OnComponentChanging(this.Component, statePrperty);
                componentChangeService.OnComponentChanged(this.Component, statePrperty, false, true);
            }
        }

       
    }
}
